using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;
using Condimar.Entities;

namespace Condimar.Repository.Mapping
{
    public class DetalleVentaMap : EntityTypeConfiguration<DetalleVenta>
    {
        public DetalleVentaMap()
        {
            // Primary Key
            this.HasKey(t => new { t.Item, t.VentaId });

            // Properties
            this.Property(t => t.Item)
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);

            this.Property(t => t.VentaId)
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);

            // Table & Column Mappings
            this.ToTable("DetalleVenta");
            this.Property(t => t.Item).HasColumnName("Item");
            this.Property(t => t.VentaId).HasColumnName("VentaId");
            this.Property(t => t.ProductoId).HasColumnName("ProductoId");
            this.Property(t => t.Cantidad).HasColumnName("Cantidad");
            this.Property(t => t.Precio).HasColumnName("Precio");

            // Relationships
            this.HasOptional(t => t.Producto)
                .WithMany(t => t.DetalleVentas)
                .HasForeignKey(d => d.ProductoId);
            this.HasRequired(t => t.Venta)
                .WithMany(t => t.DetalleVentas)
                .HasForeignKey(d => d.VentaId);

        }
    }
}
